package com.ahcloud.enhance.curator.configuration;

import lombok.Data;
import org.apache.curator.RetryPolicy;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;

/**
 * @program: distributedlock-enhance
 * @description:
 * @author: YuKai Fan
 * @create: 2024/4/30 17:14
 **/
@Data
@ConfigurationProperties(prefix = "distributed.lock.zk")
public class CuratorProperties {

    /**
     * zookeeper连接地址，多个逗号隔开
     */
    private String zkUrls;

    /**
     * session超时时间(单位：毫秒) 默认 60s
     */
    private Long sessionTimeoutMs = Long.getLong("curator-default-session-timeout", 60 * 1000);

    /**
     * 连接超时时间(单位：毫秒) 默认 15s
     */
    private Long connectionTimeoutMs = Long.getLong("curator-default-connection-timeout", 15 * 1000);

    /**
     * 重试策略配置
     */
    private RetryPolicyConfig retryPolicyConfig;

    @Data
    public static class RetryPolicyConfig {
        /**
         * 最大重试次数
         */
        private int maxRetries;

        /**
         * 重试之间等待的初始时间
         */
        private int baseSleepTimeMs;

        /**
         * 重试间隔时间
         */
        private int retryIntervalMs;

        /**
         * 给定一段时间内，重试
         */
        private int maxElapsedTimeMs;

        /**
         * 重试策略名称
         */
        private String policyName;
    }
}
